package com.deer.wms.busine.tactic.web;

import com.deer.wms.busine.tactic.model.soMerge.SoMergeTactic;
import com.deer.wms.busine.tactic.model.soMerge.SoMergeTacticCriteria;
import com.deer.wms.busine.tactic.service.SoMergeTacticService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by ll on 2020/02/04.
*/
@Api(description = "SO合并api接口")
@RestController
@RequestMapping("/so/merge/tactics")
public class SoMergeTacticController {

    @Autowired
    private SoMergeTacticService soMergeTacticService;

    @PostMapping("/insert")
    public Result add(@RequestBody SoMergeTactic soMergeTactic) {
        soMergeTacticService.save(soMergeTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(Integer id) {
        soMergeTacticService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody SoMergeTactic soMergeTactic) {
        soMergeTacticService.updateById(soMergeTactic);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/detail")
    public Result detail(Integer id) {
        SoMergeTactic soMergeTactic = soMergeTacticService.getById(id);
        return ResultGenerator.genSuccessResult(soMergeTactic);
    }

    @GetMapping("/list")
    public Result list(SoMergeTacticCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<SoMergeTactic> list = soMergeTacticService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
